:root {
    --sidebar-width: 260px;
    --sidebar-bg: #202123;
    --sidebar-text: #ececf1;
    --sidebar-hover-bg: #343541;

    --main-bg-color: #343541;
    --chat-window-bg: #444654;
    --header-bg-color: #343541;
    --input-bg-color: #40414f;
    --input-border-color: #555660;

    --user-bubble-bg: #5a5b6b;
    --user-bubble-text: #ffffff;
    --ai-bubble-bg: #3e3e4f;
    --ai-bubble-text: #ececf1;

    --send-btn-color: #10a37f;
    --send-btn-hover-color: #0c8a6f;
    --status-error-bg: #f8d7da;
    --status-error-color: #721c24;
    --status-info-bg: #d1ecf1;
    --status-info-color: #0c5460;
    --status-success-bg: #d4edda;
    --status-success-color: #155724;

    --border-color-dark: #6e6e80;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--main-bg-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden; /* 隐藏主页面的滚动条，由内部组件管理 */
    color: var(--ai-bubble-text);
}

.app-container {
    display: flex;
    width: 100vw; /* 占据整个视口宽度 */
    height: 100vh; /* 占据整个视口高度 */
    overflow: hidden; /* 隐藏容器自身的滚动条 */
}

/* 左侧边栏 */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color-dark);
    padding: 10px 0;
}

.sidebar-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color-dark);
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    margin: 0;
    font-size: 1.2em;
    color: var(--sidebar-text);
}

.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: transparent;
    color: var(--sidebar-text);
    border: 1px solid var(--border-color-dark);
    padding: 8px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}
.new-chat-btn:hover {
    background-color: var(--sidebar-hover-bg);
    border-color: var(--sidebar-hover-bg);
}

.chat-history-list {
    flex-grow: 1;
    overflow-y: auto; /* 历史记录可滚动 */
    padding: 0 10px;
}

.chat-history-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    margin-bottom: 5px;
    border-radius: 5px;
    color: var(--sidebar-text);
    text-decoration: none;
    background-color: transparent;
    transition: background-color 0.2s ease;
    white-space: nowrap; /* 不换行 */
    overflow: hidden; /* 隐藏溢出内容 */
    text-overflow: ellipsis; /* 显示省略号 */
}

.chat-history-item:hover {
    background-color: var(--sidebar-hover-bg);
}

.chat-history-item.active {
    background-color: var(--sidebar-hover-bg);
    font-weight: bold;
}

.sidebar-footer {
    padding: 10px 20px;
    border-top: 1px solid var(--border-color-dark);
    flex-shrink: 0;
}

.settings-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 10px 0;
    color: var(--sidebar-text);
    transition: opacity 0.2s ease;
}
.settings-toggle:hover {
    opacity: 0.8;
}

.settings-panel {
    background-color: var(--sidebar-bg);
    padding: 15px 0;
    border-top: 1px solid var(--border-color-dark);
    margin-top: 10px;
}

.settings-panel.hidden {
    display: none;
}

.setting-item {
    display: flex;
    flex-direction: column;
    margin-bottom: 15px;
    padding: 0 20px;
}

.settings-panel label {
    font-size: 0.9em;
    color: var(--secondary-text-color);
    margin-bottom: 5px;
}

.settings-panel input {
    padding: 8px 12px;
    border: 1px solid var(--input-border-color);
    border-radius: 5px;
    font-size: 1em;
    background-color: var(--input-bg-color);
    color: var(--sidebar-text);
}

.save-settings-btn {
    width: calc(100% - 40px);
    margin: 10px 20px 0 20px;
    padding: 10px 15px;
    background-color: var(--send-btn-color);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease;
}
.save-settings-btn:hover {
    background-color: var(--send-btn-hover-color);
}


/* 主聊天内容区域 */
.chat-main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--main-bg-color);
    overflow: hidden;
    position: relative;
}

.chat-window {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
    scroll-behavior: smooth;
    background-color: var(--chat-window-bg);
}

/* 消息样式 */
.message-wrapper {
    display: flex;
    margin-bottom: 20px;
    align-items: flex-start;
    padding: 0 10px;
}

.message-avatar {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: #a0a0a0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.3em;
    color: white;
    margin-top: 5px;
}

.message-content {
    max-width: 70%;
    padding: 15px 20px;
    border-radius: 18px;
    line-height: 1.6;
    word-wrap: break-word;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    color: var(--ai-bubble-text);
    font-size: 0.95em;
    min-width: 50px;
    overflow-wrap: break-word;
    word-break: break-word;
}

.message-text {
    color: inherit;
}

/* 用户消息 */
.message-wrapper.user {
    justify-content: flex-end;
}

.message-wrapper.user .message-content {
    background-color: var(--user-bubble-bg);
    color: var(--user-bubble-text);
    border-bottom-right-radius: 8px;
}

.message-wrapper.user .message-avatar {
    order: 2;
    margin-left: 15px;
    background-color: #4CAF50;
}

/* AI 消息 */
.message-wrapper.bot {
    justify-content: flex-start;
}

.message-wrapper.bot .message-content {
    background-color: var(--ai-bubble-bg);
    color: var(--ai-bubble-text);
    border-bottom-left-radius: 8px;
}

.message-wrapper.bot .message-avatar {
    order: 1;
    margin-right: 15px;
    background-color: #888888;
}

/* System messages */
.message-wrapper.system {
    justify-content: center;
    margin-bottom: 20px;
}
.message-wrapper.system .message-avatar {
    background-color: #f7a32b;
}
.message-wrapper.system .message-content {
    background-color: #ffe0b2;
    color: #e65100;
    font-size: 0.9em;
    text-align: center;
    max-width: 60%;
    padding: 10px 15px;
    border-radius: 10px;
}

/* 代码块的样式 */
.message-text pre {
    background-color: #282c34;
    color: #abb2bf;
    padding: 15px;
    border-radius: 5px;
    overflow-x: auto;
    margin: 10px 0;
    font-size: 0.9em;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
    border: 1px solid rgba(255,255,255,0.1);
}

.message-text code {
    font-family: 'Consolas', 'Monaco', 'Andale Mono', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
    background-color: rgba(135, 131, 120, 0.15);
    padding: 2px 4px;
    border-radius: 3px;
    color: #92b1cf;
}

/* 列表样式 */
.message-text ul, .message-text ol {
    margin-left: 20px;
    padding-left: 0;
    margin-top: 10px;
    margin-bottom: 10px;
}

.message-text li {
    margin-bottom: 5px;
}

/* 链接样式 */
.message-text a {
    color: #8ab4f8;
    text-decoration: none;
}

.message-text a:hover {
    text-decoration: underline;
}

/* 标题样式 */
.message-text h1, .message-text h2, .message-text h3, .message-text h4 {
    margin-top: 1em;
    margin-bottom: 0.5em;
    line-height: 1.2;
    color: var(--ai-bubble-text);
}
.message-text h1 { font-size: 1.8em; }
.message-text h2 { font-size: 1.6em; }
.message-text h3 { font-size: 1.4em; }

/* 段落间距 */
.message-text p {
    margin-bottom: 1em;
    line-height: 1.6;
}
.message-text p:last-child {
    margin-bottom: 0;
}

/* **新的输入区域包装器，用于固定在底部** */
.chat-input-area-wrapper {
    position: sticky; /* 粘性定位 */
    bottom: 0;
    width: 100%;
    background-color: var(--main-bg-color); /* 与主背景一致 */
    padding: 15px 20px;
    border-top: 1px solid var(--border-color-dark);
    box-sizing: border-box; /* 确保 padding 包含在宽度内 */
}

.chat-input-area {
    display: flex;
    align-items: flex-end; /* 让文本框和按钮底部对齐 */
    gap: 10px;
    max-width: 700px; /* 限制输入区域最大宽度，保持美观 */
    margin: 0 auto; /* 居中 */
    padding: 0 10px; /* 内部左右边距 */
}

/* **输入框优化** */
.chat-input-area textarea {
    flex-grow: 1;
    padding: 12px 15px;
    border: 1px solid var(--input-border-color);
    border-radius: 20px;
    font-size: 1em;
    resize: none; /* 禁用手动调整大小 */
    overflow-y: auto; /* 允许文本框内部滚动 */
    min-height: 48px; /* 增大最小高度，使其更显眼 */
    max-height: 150px; /* 限制最大高度，防止过大 */
    background-color: var(--input-bg-color);
    color: var(--ai-bubble-text);
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
    line-height: 1.5; /* 增加行高 */
}

.chat-input-area button {
    background-color: var(--send-btn-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 48px; /* 增大按钮大小 */
    height: 48px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 1.2em;
    transition: background-color 0.3s ease, transform 0.2s ease;
    flex-shrink: 0;
}

.chat-input-area button:hover {
    background-color: var(--send-btn-hover-color);
    transform: translateY(-1px);
}

.chat-input-area button svg {
    fill: currentColor;
}

.status-message {
    position: absolute;
    bottom: 80px; /* 调整位置，使其在输入框上方显示 */
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.9em;
    text-align: center;
    z-index: 100;
    white-space: nowrap;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    display: none;
}

.status-message.error {
    background-color: var(--status-error-bg);
    color: var(--status-error-color);
    border: 1px solid #f5c6cb;
}
.status-message.info {
    background-color: var(--status-info-bg);
    color: var(--status-info-color);
    border: 1px solid #bee5eb;
}
.status-message.success {
    background-color: var(--status-success-bg);
    color: var(--status-success-color);
    border: 1px solid #c3e6cb;
}

/* ===== 响应式设计 ===== */

/* 大屏幕桌面端 (1200px 及以上) */
@media screen and (min-width: 1200px) {
    .chat-input-area {
        max-width: 800px;
    }
    
    .message-content {
        max-width: 75%;
    }
    
    .sidebar {
        width: 280px;
    }
}

/* 中等屏幕桌面端 (768px - 1199px) */
@media screen and (min-width: 768px) and (max-width: 1199px) {
    .chat-input-area {
        max-width: 600px;
    }
    
    .message-content {
        max-width: 70%;
    }
    
    .sidebar {
        width: 260px;
    }
}

/* 平板端 (768px 及以下) */
@media screen and (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border-color-dark);
        flex-shrink: 0;
    }
    
    .sidebar-header {
        padding: 10px 15px;
    }
    
    .sidebar-header h2 {
        font-size: 1.1em;
    }
    
    .new-chat-btn {
        padding: 6px 12px;
        font-size: 0.85em;
    }
    
    .chat-history-list {
        max-height: 100px;
        overflow-y: auto;
    }
    
    .chat-history-item {
        padding: 8px 12px;
        font-size: 0.9em;
    }
    
    .sidebar-footer {
        padding: 8px 15px;
    }
    
    .chat-main-content {
        flex: 1;
        min-height: 0;
    }
    
    .chat-window {
        padding: 15px 10px;
    }
    
    .message-wrapper {
        padding: 0 5px;
        margin-bottom: 15px;
    }
    
    .message-content {
        max-width: 85%;
        padding: 12px 15px;
        font-size: 0.9em;
    }
    
    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 1.1em;
    }
    
    .chat-input-area-wrapper {
        padding: 10px 15px;
    }
    
    .chat-input-area {
        max-width: 100%;
        padding: 0 5px;
    }
    
    .chat-input-area textarea {
        min-height: 44px;
        padding: 10px 12px;
        font-size: 0.95em;
    }
    
    .chat-input-area button {
        width: 44px;
        height: 44px;
    }
    
    .status-message {
        bottom: 70px;
        font-size: 0.85em;
        padding: 8px 15px;
    }
    
    /* 移动端设置面板优化 */
    .settings-panel {
        padding: 10px 0;
    }
    
    .setting-item {
        padding: 0 15px;
        margin-bottom: 12px;
    }
    
    .settings-panel input {
        padding: 6px 10px;
        font-size: 0.9em;
    }
    
    .save-settings-btn {
        width: calc(100% - 30px);
        margin: 8px 15px 0 15px;
        padding: 8px 12px;
        font-size: 0.9em;
    }
}

/* 手机端 (480px 及以下) */
@media screen and (max-width: 480px) {
    .sidebar {
        max-height: 150px;
    }
    
    .sidebar-header {
        padding: 8px 12px;
    }
    
    .sidebar-header h2 {
        font-size: 1em;
    }
    
    .new-chat-btn {
        padding: 5px 10px;
        font-size: 0.8em;
        gap: 5px;
    }
    
    .chat-history-list {
        max-height: 80px;
    }
    
    .chat-history-item {
        padding: 6px 10px;
        font-size: 0.85em;
        gap: 8px;
    }
    
    .chat-window {
        padding: 10px 5px;
    }
    
    .message-wrapper {
        margin-bottom: 12px;
    }
    
    .message-content {
        max-width: 90%;
        padding: 10px 12px;
        font-size: 0.85em;
        border-radius: 15px;
    }
    
    .message-avatar {
        width: 28px;
        height: 28px;
        font-size: 1em;
        margin-top: 3px;
    }
    
    .message-wrapper.user .message-avatar {
        margin-left: 10px;
    }
    
    .message-wrapper.bot .message-avatar {
        margin-right: 10px;
    }
    
    .chat-input-area-wrapper {
        padding: 8px 10px;
    }
    
    .chat-input-area {
        gap: 8px;
    }
    
    .chat-input-area textarea {
        min-height: 40px;
        padding: 8px 10px;
        font-size: 0.9em;
        border-radius: 18px;
    }
    
    .chat-input-area button {
        width: 40px;
        height: 40px;
    }
    
    .status-message {
        bottom: 60px;
        font-size: 0.8em;
        padding: 6px 12px;
        max-width: 90%;
    }
    
    /* 移动端代码块优化 */
    .message-text pre {
        padding: 10px;
        font-size: 0.8em;
        margin: 8px 0;
    }
    
    .message-text code {
        font-size: 0.8em;
        padding: 1px 3px;
    }
    
    /* 移动端标题优化 */
    .message-text h1 { font-size: 1.4em; }
    .message-text h2 { font-size: 1.3em; }
    .message-text h3 { font-size: 1.2em; }
    
    .btn-text {
        display: none;
    }
    
    .new-chat-btn,
    .settings-toggle {
        justify-content: center;
    }
}

/* 超小屏幕 (320px 及以下) */
@media screen and (max-width: 320px) {
    .sidebar {
        max-height: 120px;
    }
    
    .chat-history-list {
        max-height: 60px;
    }
    
    .message-content {
        max-width: 95%;
        padding: 8px 10px;
        font-size: 0.8em;
    }
    
    .message-avatar {
        width: 24px;
        height: 24px;
        font-size: 0.9em;
    }
    
    .chat-input-area textarea {
        min-height: 36px;
        padding: 6px 8px;
        font-size: 0.85em;
    }
    
    .chat-input-area button {
        width: 36px;
        height: 36px;
    }
}

/* 横屏模式优化 */
@media screen and (max-height: 500px) and (orientation: landscape) {
    .sidebar {
        max-height: 100px;
    }
    
    .chat-history-list {
        max-height: 50px;
    }
    
    .chat-input-area-wrapper {
        padding: 5px 15px;
    }
    
    .chat-input-area textarea {
        min-height: 36px;
        max-height: 80px;
    }
    
    .status-message {
        bottom: 50px;
    }
}

/* 高分辨率屏幕优化 */
@media screen and (min-resolution: 2dppx) {
    .message-avatar {
        border: 0.5px solid rgba(255, 255, 255, 0.1);
    }
    
    .chat-input-area textarea {
        border-width: 0.5px;
    }
}

/* 深色模式支持 */
@media (prefers-color-scheme: dark) {
    :root {
        --sidebar-bg: #1a1a1a;
        --main-bg-color: #1a1a1a;
        --chat-window-bg: #2a2a2a;
        --input-bg-color: #3a3a3a;
    }
}

/* 减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .chat-input-area button:hover {
        transform: none;
    }
}

/* 打印样式 */
@media print {
    .sidebar,
    .chat-input-area-wrapper,
    .status-message {
        display: none !important;
    }
    
    .chat-main-content {
        width: 100% !important;
    }
    
    .chat-window {
        overflow: visible !important;
        height: auto !important;
    }
    
    .message-content {
        max-width: 100% !important;
        box-shadow: none !important;
        border: 1px solid #ccc !important;
    }
}

/* 新增元素的样式 */
.help-text {
    font-size: 0.8em;
    color: #888;
    margin-top: 4px;
    opacity: 0.8;
}

.input-help {
    font-size: 0.75em;
    color: #888;
    text-align: center;
    margin-top: 5px;
    opacity: 0.7;
}

.btn-text {
    display: inline;
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
    .chat-history-item,
    .settings-toggle,
    .new-chat-btn,
    .save-settings-btn,
    .chat-input-area button {
        min-height: 44px; /* 确保触摸目标足够大 */
    }
    
    .chat-input-area textarea {
        font-size: 16px; /* 防止iOS缩放 */
    }
}

/* 焦点状态优化 */
.chat-history-item:focus,
.settings-toggle:focus,
.new-chat-btn:focus,
.save-settings-btn:focus,
.chat-input-area button:focus,
.chat-input-area textarea:focus,
.settings-panel input:focus {
    outline: 2px solid #10a37f;
    outline-offset: 2px;
}

/* 键盘导航优化 */
.chat-history-item:focus-visible,
.settings-toggle:focus-visible,
.new-chat-btn:focus-visible,
.save-settings-btn:focus-visible,
.chat-input-area button:focus-visible {
    background-color: var(--sidebar-hover-bg);
}

/* 高对比度模式支持 */
@media (prefers-contrast: high) {
    :root {
        --border-color-dark: #ffffff;
        --input-border-color: #ffffff;
    }
    
    .message-content {
        border: 1px solid var(--border-color-dark);
    }
}

/* 输入控制区域 */
.input-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    padding: 0 5px;
}

.control-btn {
    background-color: transparent;
    color: var(--sidebar-text);
    border: 1px solid var(--border-color-dark);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.control-btn:hover {
    background-color: var(--sidebar-hover-bg);
    border-color: var(--send-btn-color);
    color: var(--send-btn-color);
}

.control-btn:active {
    transform: scale(0.95);
}

/* 文件预览区域 */
.file-preview {
    display: none;
    background-color: var(--input-bg-color);
    border: 1px solid var(--input-border-color);
    border-radius: 5px;
    padding: 10px;
    margin-top: 10px;
    max-height: 200px;
    overflow-y: auto;
}

.file-preview.show {
    display: block;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background-color: var(--main-bg-color);
    border-radius: 6px;
    margin-bottom: 8px;
}

.file-item:last-child {
    margin-bottom: 0;
}

.file-icon {
    width: 24px;
    height: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--send-btn-color);
    border-radius: 4px;
    color: white;
    font-size: 0.8em;
}

.file-info {
    flex: 1;
    min-width: 0;
}

.file-name {
    font-size: 0.9em;
    color: var(--ai-bubble-text);
    margin-bottom: 2px;
    word-break: break-all;
}

.file-size {
    font-size: 0.8em;
    color: #888;
}

.file-remove {
    background: none;
    border: none;
    color: #ff6b6b;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.file-remove:hover {
    background-color: rgba(255, 107, 107, 0.1);
}

/* 图片预览 */
.image-preview {
    max-width: 100%;
    max-height: 150px;
    border-radius: 6px;
    margin-top: 5px;
}

/* 响应式调整 */
@media screen and (max-width: 768px) {
    .input-controls {
        gap: 8px;
        margin-bottom: 8px;
    }
    
    .control-btn {
        width: 32px;
        height: 32px;
    }
    
    .file-preview {
        max-height: 150px;
    }
}

@media screen and (max-width: 480px) {
    .input-controls {
        gap: 6px;
    }
    
    .control-btn {
        width: 28px;
        height: 28px;
    }
}